import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.impute import SimpleImputer
import pandas as pd
import numpy as np

# 导入数据
data = pd.read_csv(r"C:\Users\Lenovo\Desktop\Insightful & Vast USA Statistics\每个UID的负债指数.csv")
state_name = data['state'].unique()

# 创建数据存放路径
writer = pd.ExcelWriter(r"C:\Users\Lenovo\Desktop\Insightful & Vast USA Statistics\根据state拆分的表格\拆分表格.xlsx")

# 拆分表格
for i in state_name:
    state1 = data[data['state']==i]
    state1.to_excel(writer,i)

writer.save() # 文件保存
writer.close() # 文件关闭